<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <th:block th:include="include :: header('角色添加')"/>
</head>
<body class="pear-container">
<form class="layui-form" action="">
  <div class="mainBox">
    <div class="main-container">
      <div class="main-container">
        <div class="layui-form-item">
          <label class="layui-form-label my-red-star">名称</label>
          <div class="layui-input-block">
            <input type="text" name="roleName" lay-verify="required" autocomplete="off" placeholder="请输入 "
                   class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label my-red-star">标识</label>
          <div class="layui-input-block">
            <input type="text" name="roleCode" lay-verify="required" autocomplete="off" placeholder="请输入 "
                   class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label my-red-star">状态</label>
          <div class="layui-input-block">
            <input type="radio" name="enable" value="0" title="开启">
            <input type="radio" name="enable" value="1" title="关闭" checked>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">排序</label>
          <div class="layui-input-block">
            <input type="text" name="sort" autocomplete="off" placeholder="请输入 "
                   class="layui-input">
          </div>
        </div>
        <div class="layui-form-item layui-form-text">
          <label class="layui-form-label">描述</label>
          <div class="layui-input-block">
            <textarea placeholder="请输入描述" name="details" class="layui-textarea"></textarea>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="bottom">
    <div class="button-container">
      <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="role-save">
        <i class="layui-icon layui-icon-ok"></i>
        提交
      </button>
      <button type="reset" class="pear-btn pear-btn-sm">
        <i class="layui-icon layui-icon-refresh"></i>
        重置
      </button>
    </div>
  </div>
</form>

<th:block th:include="include :: footer"/>
<script>

  layui.use(['table', 'form', 'jquery', 'upload', 'popup'], function () {
    let form = layui.form;
    let $ = layui.jquery;

    form.on('submit(role-save)', function (data) {
      $.ajax({
        url: suffix + '/role/save',
        data: data.field,
        dataType: 'json',
        type: 'post',
        success: function (res) {
          if (res.success) {
            layer.msg(res.msg, {icon: 1, time: 1000}, function () {
              parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
              parent.layui.table.reload("user-table");
            });
          } else {
            layer.msg(res.msg, {icon: 2, time: 1000});
          }
        }
      })
      return false;
    });


  })
</script>
</body>
</html>

